var e = require("util.js"), n = (require("enums.js"), require("md5.js"), function(e, n) {
    for (var t = [], i = 0; i < e.length; ++i) i >= n && t.push(e[i]);
    return t;
}), t = function(n) {
    var t = {
        data: null,
        success: null,
        fail: null
    }, i = function(n) {
        var i = 0;
        "function" != typeof n[0] && (e.extend(t, {
            data: n[0]
        }), ++i), n.length > i && (t.success = n[i], n.length >= i + 2 && (t.fail = n[i + 1]));
    };
    return "function" == typeof n[0] || n.length > 1 && "function" == typeof n[1] ? i(n) : 1 == n.length && void 0 !== n[0].length ? i(n[0]) : (t.data = n[0], 
    i(n[1])), t;
}, i = function(i, r) {
    var o = t(n(arguments, 1));
    e.request(i, o.data, "GET", o.success, o.fail);
}, r = function(i, r) {
    var o = t(n(arguments, 1));
    e.request(i, o.data, "POST", o.success, o.fail);
}, o = function() {
    return getApp().globalData.locationInfo || {};
};

module.exports = {
    commonSmsCode: function() {
        i("/Api/Common/SendVerifySms", {
            type: 1
        }, arguments);
    },
    commonUpload: function(n, t, i) {
        if (n) {
            var r = n instanceof Array, o = [], d = r ? n : [ n ];
            if (d.length) {
                !function n(u) {
                    u = u || 0, e.upload(d[u], null, function(e) {
                        o.push(e), o.length != d.length ? t && ++u < d.length && n(u) : i && i(r ? o : o[0]);
                    }), !t && ++u < d.length && n(u);
                }();
            }
        }
    },
    homeNearestSchool: function() {
        i("/Api/Home/NearestSchool", {
            longitude: 0,
            latitude: 0,
            school: ""
        }, arguments);
    },
    homeIndex: function() {
        i("/Api/Home/Index", {
            pageIndex: 0,
            pageSize: 10
        }, arguments);
    },
    homeMine: function() {
        i("/Api/Home/Mine", {
            mine: ""
        }, arguments);
    },
    shopShopIndex: function() {
        i("/Api/Shop/Index", {
            id: 0,
            type: ""
        }, arguments);
    },
    shopCommodityList: function() {
        i("/Api/Shop/CommodityList", {
            commodityList: ""
        }, arguments);
    },
    loginWechat: function() {
        i("/Api/Login/LoginWechat", {
            wechat: ""
        }, arguments);
    },
    updateWechatInfo: function() {
        r("/Api/User/UpdateUserInfo", arguments);
    },
    orderErrandList: function() {
        i("/Api/Order/ErrandOrderList", {
            stype: 0,
            pageIndex: 0,
            pageSize: 10,
            errandlist: ""
        }, arguments);
    },
    orderErrandPrepare: function() {
        i("/Api/Order/ErrandOrderPrepare", {
            errandPrepare: ""
        }, arguments);
    },
    orderTakeoutPrepare: function() {
        i("/Api/Order/TakeoutOrderPrepare", {
            takeoutPrepare: ""
        }, arguments);
    },
    orderAcceptInfo: function() {
        i("/Api/Order/OrderInfoForAccept", {
            forAccept: ""
        }, arguments);
    },
    orderInfo: function() {
        i("/Api/Order/OrderInfo", arguments);
    },
    orderList: function() {
        i("/Api/Order/OrderList", {
            role: 1,
            pageIndex: 0,
            pageSize: 10
        }, arguments);
    },
    orderCommit: function() {
        r("/Api/Order/OrderCommit", {
            latitude: o().latitude,
            longitude: o().longitude
        }, arguments);
    },
    orderAccept: function() {
        i("/Api/Order/OrderAccept", {
            latitude: o().latitude,
            longitude: o().longitude,
            accept: ""
        }, arguments);
    },
    orderPayment: function(n, t, r) {
        i("/Api/Order/OrderPayment", e.extend({
            money: 0,
            payment: ""
        }, n), function(n) {
            if (n.IsSuccess) wx.requestPayment({
                timeStamp: n.TimeStamp,
                nonceStr: n.NonceStr,
                package: n.Package,
                signType: n.SignType,
                paySign: n.PaySign,
                success: function(e) {
                    t && t(e);
                },
                fail: function(n) {
                    "requestPayment:fail cancel" == n.errMsg ? r && r(n) : e.toast(n.errMsg);
                },
                complete: function(e) {
                    "requestPayment:cancel" == e.errMsg && r && r(e);
                }
            }); else {
                var i = getCurrentPages();
                i.length && i[i.length - 1].route.indexOf("order/_/info") >= 0 ? e.toast(n.ErrorMessage) : t && t();
            }
        });
    },
    orderFinish: function() {
        i("/Api/Order/OrderFinish", {
            finish: ""
        }, arguments);
    },
    orderCancel: function() {
        i("/Api/Order/OrderCancel", {
            cancel: ""
        }, arguments);
    },
    orderGiveup: function() {
        i("/Api/Order/OrderGiveup", {
            giveup: ""
        }, arguments);
    },
    orderRefund: function() {
        i("/Api/Order/OrderRefund", {
            refund: ""
        }, arguments);
    },
    orderComment: function() {
        i("/Api/Order/OrderComment", {
            comment: ""
        }, arguments);
    },
    couponList: function() {
        i("/Api/Coupon/List", arguments);
    },
    studentVerify: function() {
        r("/Api/Student/SaveStudentInfo", arguments);
    },
    studentRanking: function() {
        i("/Api/Student/GeDelivererList", arguments);
    },
    studentInfo: function() {
        i("/Api/Student/GetStudentInfo", arguments);
    },
    getAssginSetting: function() {
        i("/Api/UserSetting/GetSetting", {
            errandSetting: ""
        }, arguments);
    },
    updateAssignSetting: function() {
        i("/Api/UserSetting/UpdateAssignSettings", arguments);
    },
    schoolList: function() {
        i("/Api/School/GetSchoolList", arguments);
    },
    commonAddressList: function() {
        i("/Api/UserAddress/CommonAddressList", {
            commonList: ""
        }, arguments);
    },
    userAddressList: function() {
        i("/Api/UserAddress/AddressList", arguments);
    },
    userAddressInfo: function() {
        i("/Api/UserAddress/AddressInfo", arguments);
    },
    userAddressDelete: function() {
        i("/Api/UserAddress/DeleteInfo", {
            delete: ""
        }, arguments);
    },
    userAddressSave: function() {
        r("/Api/UserAddress/SaveOrUpdateInfo", arguments);
    },
    userSaveFormId: function() {
        arguments[0] && arguments[0].formId && /^[A-Za-z\d\+\/\=]+$/.test(arguments[0].formId) ? i("/Api/User/SaveWechatFormId", arguments) : console.log("Not found form_id.");
    },
    userBindMobile: function() {
        i("/Api/User/BindMobile", {
            bindMobile: ""
        }, arguments);
    },
    userBindWechatMobile: function() {
        i("/Api/User/BindWechatMobile", {
            bindWechatMobile: ""
        }, arguments);
    },
    userAccount: function() {
        i("/Api/UserAccount/AccountInfo", {
            pageIndex: 0,
            pageSize: 10
        }, arguments);
    },
    userWithdrawPrepare: function() {
        i("/Api/UserAccount/WithdrawPrepare", {
            pageIndex: 0,
            pageSize: 10,
            withdrawPrepare: ""
        }, arguments);
    },
    userWithdraw: function() {
        i("/Api/UserAccount/Withdraw", {
            withdraw: ""
        }, arguments);
    },
    userCoin: function() {
        i("/Api/UserCoin/CoinInfo", {
            pageIndex: 0,
            pageSize: 10
        }, arguments);
    },
    adminHomeIndex: function() {
        i("/Admin/Home/Index", {
            pageIndex: 0,
            pageSize: 10
        }, arguments);
    },
    adminUserInfo: function() {
        i("/Admin/User/Info", arguments);
    },
    adminUserList: function() {
        i("/Admin/User/List", {
            pageIndex: 0,
            pageSize: 10
        }, arguments);
    },
    adminStudentAudit: function() {
        i("/Admin/User/StudentAudit", {
            remark: ""
        }, arguments);
    },
    adminStudentInfo: function() {
        i("/Admin/User/StudentInfo", {
            student: ""
        }, arguments);
    },
    adminSchoolList: function() {
        i("/Admin/School/List", {
            pageIndex: 0,
            pageSize: 10
        }, arguments);
    },
    adminOrderList: function() {
        i("/Admin/Order/List", {
            pageIndex: 0,
            pageSize: 10
        }, arguments);
    },
    adminOrderInfo: function() {
        i("/Admin/Order/Info", arguments);
    },
    adminOrderPaymentInfo: function() {
        i("/Admin/Order/PaymentInfo", {
            paymentInfo: ""
        }, arguments);
    },
    adminOrderRefund: function() {
        i("/Admin/Order/Refund", {
            refund: ""
        }, arguments);
    },
    adminCheckPayment: function() {
        i("/Admin/Order/CheckPayment", {
            checkPayment: ""
        }, arguments);
    },
    adminCheckRefund: function() {
        i("/Admin/Order/CheckRefund", {
            checkRefund: ""
        }, arguments);
    },
    adminCommonAddressList: function() {
        i("/Admin/UserAddress/CommonList", {
            pageIndex: 0,
            pageSize: 10,
            common: ""
        }, arguments);
    }
};